﻿@model Zatify.WebUI.Admin.Models.UsersListViewModel
@using (Html.BeginForm("Update", "Users"))
{ 
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <thead>
            <tr>
                @if (Model.CurrentUserRole == Zatify.Domain.Abstract.UserRole.SystemAdmin)
                {
                    <th>
                    </th>
                    <th>
                        Actions
                    </th>
                }
                <th>
                    User ID
                </th>
                <th>
                    Email
                </th>
                <th>
                    Phone
                </th>
                <th>
                    Pushes
                </th>
                <th>
                    Check-Ins
                </th>
                <th>
                    Reg. State
                </th>
                <th>
                    Reg. City
                </th>
                <th>
                    <a href="@Url.Action("List", new
                        {
                            page = Model.PagingInfo.CurrentPage,
                            userID = Model.SearchModel.UserID,
                            email = Model.SearchModel.Email,
                            phone = Model.SearchModel.Phone,
                            sortOrder = (Model.SortOrder == "RegDate" ? "RegDate desc" : "RegDate")
                        })">Reg. Date</a>
                </th>
            </tr>
        </thead>
        <tbody>
            @foreach (var user in Model.Users)
            {
                if (user.Id == Model.SelectedUserID)
                { 
                <tr>
                    @if (Model.CurrentUserRole == Zatify.Domain.Abstract.UserRole.SystemAdmin)
                    {
                        <td>
                            <input type="checkbox" class="userCheck" disabled="disabled" />
                        </td>
                        <td>
                            @Html.Hidden("user.Id", user.Id)
                            @Html.Hidden("user.Login", user.Login)
                            @Html.Hidden("page", Model.PagingInfo.CurrentPage)
                            @Html.Hidden("searchUserModel.UserID", Model.SearchModel.UserID)
                            @Html.Hidden("searchUserModel.Email", Model.SearchModel.Email)
                            @Html.Hidden("searchUserModel.Phone", Model.SearchModel.Phone)
                            <input type="image" src="@Url.Content("~/Areas/Admin/Content/zatify/Images/ok.png")" title="Save" style="width: 16px; height: 16px;" />
                            <a href="@Url.Action("List", new
                                {
                                    page = Model.PagingInfo.CurrentPage,
                                    userID = Model.SearchModel.UserID,
                                    email = Model.SearchModel.Email,
                                    phone = Model.SearchModel.Phone,
                                    sortOrder = Model.SortOrder
                                })">
                                <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/cancel.png")" alt="Cancel" title="Cancel" style="width: 16px; height: 16px;" />
                            </a>
                        </td>
                    }
                    <td>
                        @user.Login
                    </td>
                    <td>
                        @Html.TextBoxFor(u => user.Email)
                    </td>
                    <td>
                        @Html.TextBoxFor(u => user.Phone)
                    </td>
                    <td>
                        @user.Pushes
                    </td>
                    <td>
                        @user.CheckIns
                    </td>
                    <td>
                        @Html.TextBoxFor(u => user.RegState)
                    </td>
                    <td>
                        @Html.TextBoxFor(u => user.RegCity)
                    </td>
                </tr>
                }
                else
                {
                <tr>
                    @if (Model.CurrentUserRole == Zatify.Domain.Abstract.UserRole.SystemAdmin)
                    {
                        <td>
                            <input type="checkbox" class="userChecked" value="@user.Id" />
                        </td>
                        <td>
                            <a href="@Url.Action("List", new
                                {
                                    page = Model.PagingInfo.CurrentPage,
                                    id = user.Id,
                                    userID = Model.SearchModel.UserID,
                                    email = Model.SearchModel.Email,
                                    phone = Model.SearchModel.Phone,
                                    sortOrder = Model.SortOrder
                                })" title="Edit">
                                <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/edit_icon.png")" alt="Edit" />
                            </a><a href="@Url.Action("Delete", new { id = user.Id })" title="Delete"  onclick="return confirm('Are you sure you want to delete this user?');">
                                <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/delete_icon.gif")" alt="Delete" />
                            </a><a href="#" title="Change password" onclick="changePassword(@user.Id)">
                                <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/password_icon.png")" alt="Change password" />
                            </a>
                            @if (user.IsActive)
                            {
                                <a href="@Url.Action("ChangeUserStatus", new { page = 1, id = user.Id, activate = 0 })" title="Inactivate" onclick="return confirm('Are you sure you want to Inactivate this user?');">
                                    <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/active_icon.png")" alt="Inactivate" />
                                </a>
                            }
                            else
                            {
                                <a href="@Url.Action("ChangeUserStatus", new { page = 1, id = user.Id, activate = 1 })" title="Activate" onclick="return confirm('Are you sure you want to Activate this user?');">
                                    <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/suspend_icon.png")" alt="Activate" />
                                </a>
                            }
                        </td>
                    }
                    <td>
                        @user.Login
                    </td>
                    <td>
                        @user.Email
                    </td>
                    <td>
                        @user.Phone
                    </td>
                    <td>
                        @user.Pushes
                    </td>
                    <td>
                        @user.CheckIns
                    </td>
                    <td>
                        @user.RegState
                    </td>
                    <td>
                        @user.RegCity
                    </td>
                    <td>
                        @user.DateAdded.ToShortDateString()
                    </td>
                </tr>
                }
            }
        </tbody>
    </table>
}